package frisbeeapproximation;

import java.util.Scanner;

public class FrisbeeApproximation {

    private static double x;
    private static double y;
    private static double vx;
    private static double vy;
    private static final double g = -9.81;
    private static final double m = 0.175;
    private static final double RHO = 1.23; //Air Density
    private static final double AREA = 0.0568; //Standard Fribee Area
    private static final double CL0 = 0.1; //Lift Coefficient
    private static final double CLA = 1.4;
    private static final double CD0 = 0.08; //Drag Coefficient
    private static final double CDA = 2.72;
    private static final double ALPHA0 = -4;

    public static void simulate(double y0, double vx0, double vy0,
            double alpha, double deltaT) {

        double cl = CL0 + CLA * alpha * Math.PI / 180;

        double cd = CD0 + CDA * Math.pow((alpha - ALPHA0) * Math.PI / 180, 2);
        x = 0;
        y = y0;
        vx = vx0;
        vy = vy0;
        int k = 0;

        while (y > 0) {

            double deltavy = (RHO * Math.pow(vx, 2) * AREA * cl / 2 / m + g) * deltaT;

            double deltavx = -RHO * Math.pow(vx, 2) * AREA * cd * deltaT;

            vx = vx + deltavx;
            vy = vy + deltavy;
            x = x + vx * deltaT;
            y = y + vy * deltaT;

            if (k % 10 == 0) {
                System.out.println(x + "," + y + "," + vx);
            }
            k++;
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter in an initial height in meters:");
        double y0 = scan.nextDouble();
        System.out.println("Enter in an initial vertical velocity in meters per second:");
        double vx0 = scan.nextDouble();
        System.out.println("Enter in an initial horizontal velocity in meters per second:");
        double vy0 = scan.nextDouble();
        System.out.println("Enter in the angle that the shooter is at:");
        double alpha = scan.nextDouble();
        System.out.println("Enter in the change in time:");
        double deltaT = scan.nextDouble();
        simulate(y0, vx0, vy0, alpha, deltaT);
    }
}